import { history, useModel } from 'umi';
import PageHeader from '@/components/page/PageHeader';
import ListReport from '@/components/report/ReportTable';
import _ from 'lodash';
import KeepAlive from 'react-activation';
export default () => {
  const { permTypes, extendProps } = useModel('sysInfo', (ret) => ({
    permTypes: ret.getCurPermTypes(),
    extendProps: ret.getCurExtendProps(),
  }));
  if (_.isEmpty(permTypes)) {
    return <></>;
  }
  const path = history.location.pathname;
  const index = path.lastIndexOf('/');

  let groupByIndex = 3;
  if (permTypes.indexOf('4') !== -1 || permTypes.indexOf('L') !== -1) {
    groupByIndex = 1;
  } else if (permTypes.indexOf('3') !== -1) {
    groupByIndex = 2;
  }
  const reptName = path.substring(index + 1, path.length);
  extendProps.groupByIndex = groupByIndex;
  return (
    <PageHeader>
      <KeepAlive key={path} when={true} name={path} id={path} saveScrollPosition={true}>
        <ListReport reportName={reptName} {...extendProps} />
      </KeepAlive>
    </PageHeader>
  );
};
